{% load i18n %}
<script type="text/javascript">
    var SEAFILE_GLOBAL = {
        csrfCookieName: '{{ CSRF_COOKIE_NAME }}'
    };

    {% if can_edit %}
    var interval;
    {% if not share_link_token %}
    var refreshLock = function() {
        $.ajax({
            url: '{% url "api-v2.1-file-view" repo_id %}' + '?p={{path|urlencode}}',
            type: 'PUT',
            dataType: 'json',
            data: {
                'operation': 'refresh-lock'
            },
            cache: false,
            beforeSend: prepareCSRFToken,
            success: function(data) {
            },
            error: function(xhr) {
                if (xhr.responseText) {
                    feedback(JSON.parse(xhr.responseText).error_msg, 'error');
                } else {
                    feedback("{% trans "Failed. Please check the network." %}", 'error');
                }
                clearInterval(interval);
            }
        });
    };
    {% else %}
    var refreshLock = function() {
        $.ajax({
            url: '{% url "api-v2.1-share-link-online-office-lock" share_link_token %}',
            type: 'PUT',
            dataType: 'json',
            cache: false,
            beforeSend: prepareCSRFToken,
            success: function(data) {
            },
            error: function(xhr) {
                if (xhr.responseText) {
                    feedback(JSON.parse(xhr.responseText).error_msg, 'error');
                } else {
                    feedback("{% trans "Failed. Please check the network." %}", 'error');
                }
                clearInterval(interval);
            }
        });
    };
    {% endif %}
    interval = setInterval(refreshLock, 60 * 1000);
    {% endif %}
</script>
{% if enable_watermark %}
<script type="text/javascript" src="{{ MEDIA_URL }}js/watermark.js"></script>
<script type="text/javascript">{% include "snippets/add_watermark.html" %}</script>
{% endif %}
